package com.intct.utils;

import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;

/**
 * @author gufg
 * @since 2025-09-22 14:46
 */
public class RowKeyUilt {
    public static String getRowkey(String rowkey, int numRegions) {
        // 获取key的hashcode
        int rowkeyHashCode = Math.abs(rowkey.hashCode()) % numRegions;

        // 左补零
        String rowkeyStr = StringUtils.leftPad(String.valueOf(rowkeyHashCode), 4, "0");

        // MD5
        String md5String = DigestUtils.md5Hex(rowkey).substring(0, 12);

        return rowkeyStr + md5String;
    }
}
